/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.viweb.storemanager.entity;

import com.viweb.storemanager.core.PropertyIndex;
import com.viweb.storemanager.core.SafeObject;
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.ArrayList;
import java.util.Locale;

/**
 *
 * @author nhchung
 */
public class TypeCategory extends BaseEntity implements Comparable, Cloneable, SafeObject, PropertyIndex {

    //khai báo biến
    protected Object cloner;
    private String name;
    private ArrayList<Category> categorys = new ArrayList<Category>();

    //khai báo hảm khởi tạo
    public TypeCategory() {
    }

    public TypeCategory(int id, String name) {
        setId(id);
        setName(name);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ArrayList<Category> getCategorys() {
        return categorys;
    }

    public void setCategorys(ArrayList<Category> categorys) {
        this.categorys = categorys;
    }

    public Object getCloner() {
        return this.cloner;
    }

    public boolean validate() {
        if (this.getName().equals("")) {
            this.setValidDescription("Tên kho không được để rỗng.");
            return false;
        }

        return true;
    }

    public Object getPropertyValue(int index) {
        String value = "";
        switch (index) {
            case 1:
                value = String.valueOf(getId());
                break;
            case 2:
                value = getName();
                break;
            case 3:
                value = getDatemodifies().toString();
                break;
            case 4:
                value = String.valueOf(getStatus());
                break;
            case 5:
                value = getNote();
                break;
        }
        return value;
    }

    public void setPropertyValue(int index, Object value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Class getPropertyClass(int index) {
        return String.class;
    }

    public int compareTo(Object object) {
        if (!(object instanceof WareHouse)) {
            throw new ClassCastException("Ngoại lệ: đối tượng thức uống không hợp lệ!");
        }

        RuleBasedCollator viCollator = (RuleBasedCollator) Collator.getInstance(new Locale("vi"));
        return viCollator.compare(this.getName(), ((TypeCategory) object).getName());
    }

    public void backup() {
        try {
            this.cloner = this.clone();
        } catch (CloneNotSupportedException ex) {
        }
    }

    public void restore() {
        this.setName(((TypeCategory) getCloner()).getName());
    }

    @Override
    public String toString() {
        return this.getName();
    }
}
